import request from '@/utils/request'
import { getToken } from '@/utils/auth'

const FILE_API = process.env.VUE_APP_FILE_API

export function fileUpload(data) {
  return request({
    url: FILE_API + '/fileInfo/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function filesUpload(data) {
  return request({
    url: FILE_API + '/fileInfo/batchUpload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

export function fileDelete(params) {
  return request({
    url: FILE_API + '/fileInfo/delete',
    method: 'delete',
    headers: {
      'Content-Type': 'application/json'
    },
    params
  })
}

export function fileListDelete(data) {
  return request({
    url: FILE_API + '/fileInfo/deletes',
    method: 'delete',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

export function fileDownload(params) {
  return request({
    url: FILE_API + '/fileInfo/download',
    method: 'get',
    params,
    headers: { 'Content-Type': 'application/json' },
    responseType: 'arraybuffer'
  })
}

export function dataFlow(params) {
  return request({
    url: FILE_API + '/fileInfo/read',
    method: 'get',
    params,
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': getToken()
    }
  })
}
